import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if false, the item will hidden in breadcrumb(default is true)
  }
**/
export const constantRouterMap = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'dashboard', noCache: true }
      }
    ]
  },

  {
    path: '/system',
    component: Layout,
    redirect: '/system/user',
    name: 'System',
    meta: {
      title: '系统管理',
      icon: 'nested'
    },

    children: [
      {
        path: '/system/user',
        component: () => import('@/views/system/user'), // Parent router-view
        name: 'SystemUser',
        meta: { title: '用户管理', noCache: true }
      },
      {
        path: '/system/role',
        component: () => import('@/views/system/role'),
        name: 'SystemRole',
        meta: { title: '角色管理', noCache: true }
      },
      {
        path: '/system/privilege',
        component: () => import('@/views/system/privilege'),
        name: 'SystemPrivilege',
        meta: { title: '权限管理', noCache: true }
      }
    ]
  },

  {
    path: '/product',
    component: Layout,
    redirect: '/product/new_product',
    name: 'Product',
    meta: {
      title: '商品管理',
      icon: 'nested'
    },

    children: [
      {
        path: '/product/new_product',
        component: () => import('@/views/system/user'), // Parent router-view
        name: 'NewProduct',
        meta: { title: '新增商品', noCache: true }
      },
      {
        path: '/product/product_list',
        component: () => import('@/views/system/user'),
        name: 'ProductList',
        meta: { title: '商品列表', noCache: true }
      },
      {
        path: '/product/product_stock',
        component: () => import('@/views/system/user'),
        name: 'ProductStock',
        meta: { title: '库存管理', noCache: true }
      }
    ]
  },

  {
    path: '/order',
    component: Layout,
    redirect: '/order/order_list',
    name: 'Order',
    meta: {
      title: '订单管理',
      icon: 'nested'
    },

    children: [
      {
        path: '/order/order_list',
        component: () => import('@/views/system/user'), // Parent router-view
        name: 'OrderList',
        meta: { title: '订单列表', noCache: true }
      },
      {
        path: '/order/order_report',
        component: () => import('@/views/system/user'),
        name: 'OrderReport',
        meta: { title: '订单统计', noCache: true }
      }
    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})
